import axios from '@/utils/axiosConfig';

export const login = async (credentials) => {
  try {
    const response = await axios.post('/auth/login', credentials);
    return {
      success: true,
      data: response.data
    };
  } catch (error) {
    return {
      success: false,
      error: error.response?.data?.message || '登录失败'
    };
  }
};

export const getUserProfile = async () => {
  try {
    const response = await axios.get('/auth/profile');
    return {
      success: true,
      data: response.data.data
    };
  } catch (error) {
    return {
      success: false,
      error: error.response?.data?.message || '获取用户信息失败'
    };
  }
};

export const updateUserProfile = async (userInfo) => {
  try {
    const response = await axios.put('/auth/profile', userInfo);
    return {
      success: true,
      data: response.data
    };
  } catch (error) {
    return {
      success: false,
      error: error.response?.data?.message || '更新用户信息失败'
    };
  }
};

export const uploadAvatar = async (formData) => {
  try {
    const response = await axios.post('/auth/upload-avatar', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    });
    return {
      success: true,
      data: response.data
    };
  } catch (error) {
    return {
      success: false,
      error: error.response?.data?.message || '头像上传失败'
    };
  }
};}]}}}